////////////////////////////////////////////////////////
// CodePlex - metacpp
//--------------------
// This file is part of "metacpp" project on CodePlex. The
// goal if the project is to demonstrate basic techniques
// used in C++ metaprogrammins.
// For more info and comments please visit:
// http://www.codeplex.com/metacpp/
////////////////////////////////////////////////////////

#include <iostream>
#include <string>

///////////////////////////////////
// STATIC CONDITION
// compile-time "if"

template<bool cond, typename T1, typename T2>
struct static_if {
	typedef T1 type;
};

template<typename T1, typename T2>
struct static_if<false, T1, T2> {
	typedef T2 type;
};


// Usage:

template<typename T, typename U>
class Buffer {
	typedef
		typename static_if<sizeof(T) >= sizeof(U), T, U>::type
		BiggestType;

	char buf[sizeof(BiggestType)];
};

void show_static_condition(void) {
	std::cout << "SHOW STATIC CONDITION" << std::endl;
	std::cout << "Size of int is " << sizeof(int)
		<< ", of std::string is " << sizeof(std::string)
		<< ", biggest is " << sizeof(Buffer<int, std::string>)
		<< " (yes, " << sizeof(Buffer<std::string, int>) << ')'
		<< std::endl;
}